///*
// *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
// *
// *  Redistribution and use in source and binary forms, with or without
// *  modification, are permitted provided that the following conditions are met:
// *
// *  Redistributions of source code must retain the above copyright notice,
// *  this list of conditions and the following disclaimer.
// *  Redistributions in binary form must reproduce the above copyright
// *  notice, this list of conditions and the following disclaimer in the
// *  documentation and/or other materials provided with the distribution.
// *  Neither the name of the dreamlu.net developer nor the names of its
// *  contributors may be used to endorse or promote products derived from
// *  this software without specific prior written permission.
// *  Author: Chill 庄骞 (smallchill@163.com)
// */
//package com.plian.system.controller.fr.evaluation;
//
//import com.alibaba.fastjson.JSON;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.fasterxml.jackson.core.type.TypeReference;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.plian.Tools.*;
//import com.plian.Tools.base.BaseController;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.common.status.CustomCode;
//import com.plian.system.config.Resubmit;
//import com.plian.system.entity.fr.evaluation.AssetAppraiserInfo;
//import com.plian.system.entity.fr.evaluation.EvaluationApproval;
//import com.plian.system.entity.fr.evaluation.EvaluationValue;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.ObjResult;
//import com.plian.system.model.token.PassToken;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.search.TokenSearch;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.fr.evaluation.IAssetAppraiserInfoService;
//import com.plian.system.service.fr.evaluation.IEvaluationApprovalService;
//import com.plian.system.service.fr.evaluation.IEvaluationValueService;
//import com.plian.system.vo.fr.evaluation.EvaluationApprovalVO;
//import com.plian.system.wrapper.fr.evaluation.AssetAppraiserInfoWrapper;
//import com.plian.system.wrapper.fr.evaluation.EvaluationApprovalWrapper;
//import com.plian.system.wrapper.fr.evaluation.EvaluationValueWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang.exception.ExceptionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.core.io.FileSystemResource;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Optional;
//
///**
// * 资产评估项目核准与备案 控制器
// *
// * @author jianglei
// * @since 2019-10-21
// */
//
//@Slf4j
//@RestController
//@AllArgsConstructor
//@RequestMapping("api/evaluationapproval")
//public class EvaluationApprovalController extends BaseController {
//
//	private IEvaluationApprovalService evaluationApprovalService;
//
//	private IEvaluationValueService evaluationValueService;
//
//	private IAssetAppraiserInfoService assetAppraiserInfoService;
//
//	private AssetAppraiserInfoWrapper assetAppraiserInfoWrapper;
//
//	private EvaluationApprovalWrapper evaluationApprovalWrapper;
//
//	private EvaluationValueWrapper evaluationValueWrapper;
//
//
//    /**
//    * 详情
//    */
//	@PostMapping("/detail")
//	public ObjResult detail(@Valid @RequestBody EvaluationApproval evaluationApproval) {
//		ObjResult objResult;
//		try{
//			EvaluationApproval detail = evaluationApprovalService.getOne(Condition.getQueryWrapper(evaluationApproval));
//			objResult = new ObjResult(CommonCode.SUCCESS);
//			if (Optional.ofNullable(detail).isPresent()) {
//				PageData pd = new PageData();
//				EvaluationValue evaluationValue = new EvaluationValue();
//				evaluationValue.setEvaluationApprovalId(detail.getId());
//				pd.put("evaluationValues", evaluationValueWrapper.entityToVO(evaluationValueService.list(Condition.getQueryWrapper(evaluationValue))));
//
//				AssetAppraiserInfo assetAppraiserInfo = new AssetAppraiserInfo();
//				assetAppraiserInfo.setEvaluationApprovalId(detail.getId());
//				pd.put("assetAppraiserInfos", assetAppraiserInfoWrapper.entityToVO(assetAppraiserInfoService.list(Condition.getQueryWrapper(assetAppraiserInfo))));
//
//				EvaluationApprovalVO evaluationApprovalVO = evaluationApprovalWrapper.entityToVO(detail);
//
//				ObjectMapper mapper = new ObjectMapper();
//				String json = JSON.toJSONStringWithDateFormat(evaluationApprovalVO, DateUtil.PATTERN_DATETIME);
//				pd.putAll(mapper.readValue(json, new TypeReference<HashMap<String, String>>(){}));
//				objResult.setPageData(pd);
//			}
//		} catch (Exception e) {
//			log.error(ExceptionUtils.getFullStackTrace(e));
//			objResult = new ObjResult(CommonCode.ERROR);
//			return objResult;
//		}
//
//		return objResult;
//	}
//
//	/**
//	* 分页 资产评估项目核准与备案
//	*/
//	@PostMapping("/list")
//	public ListResult<EvaluationApprovalVO> list(@Valid @RequestBody Query query) {
//		List<SearchEntity> entityList = query.getSearch();
//
//		if (query.getAscs()==null&&query.getDescs()==null){
//			query.setDescs("create_time");
//		}
//
//		QueryWrapper<EvaluationApproval> queryWrapper = SearchParamEntiy.getQueryWrapper(Condition.getQueryWrapper(new EvaluationApproval()), entityList);
//		TokenSearch<EvaluationApproval> tokenSearch = new TokenSearch<>();
//		tokenSearch.addTokenQuery(queryWrapper, query);
//
//		IPage<EvaluationApproval> pages = evaluationApprovalService.page(Condition.getPage(query), queryWrapper);
//		List<EvaluationApprovalVO> evaluationApprovalVOS = evaluationApprovalWrapper.entityToVO(pages.getRecords());
//		ListResult<EvaluationApprovalVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//		listResult.setList(evaluationApprovalVOS);
//		listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//		return listResult;
//	}
//
//
//
//	/**
//	* 新增或修改 资产评估项目核准与备案
//	*/
//	@PostMapping("/submit")
//	@Resubmit(delaySeconds = 0)
//	public ObjResult submit(@Valid @RequestBody EvaluationApproval evaluationApproval) {
//		if (!(Optional.ofNullable(evaluationApproval).isPresent() && Optional.ofNullable(evaluationApproval.getStatus()).isPresent()
//				&& evaluationApproval.getStatus() == -1)) {
//			if (!evaluationApprovalService.checkIsExisted(evaluationApproval.getId(),
//					evaluationApproval.getApprovalCode(), evaluationApproval.getFilingCode())) {
//				return new ObjResult(CustomCode.builder().message("核准编号或备案编号已存在").code(1999).success(false).build());
//			}
//		}
//
//		return evaluationApprovalService.submit(evaluationApproval)
//				? new ObjResult(CommonCode.SUCCESS) : new ObjResult(CommonCode.FAIL);
//
//	}
//
//
//
//
//	/**
//	* 删除 资产评估项目核准与备案
//	*/
//	@PostMapping("/remove")
//	public ObjResult remove(@RequestBody PageData pd) {
//		ObjResult objResult;
//		List<String> ids = (List<String>)pd.get("ids");
//		if (evaluationApprovalService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))){
//			objResult = new ObjResult(CommonCode.SUCCESS);
//			return objResult;
//		}else {
//			objResult = new ObjResult(CommonCode.FAIL);
//		}
//		return objResult;
//	}
//
//
//	/**
//	 * 变更 资产评估项目核准与备案
//	 */
//	@PostMapping("/change")
//	public ObjResult change(@Valid @RequestBody EvaluationApproval evaluationApproval) {
//		ObjResult objResult;
//		if (StringUtil.isBlank(evaluationApproval.getApprovalCode())) {
//			return new ObjResult(CustomCode.builder().message("核准编号不能为空").code(1999).success(false).build());
//
//		}
//		if (StringUtil.isBlank(evaluationApproval.getFilingCode())) {
//			return new ObjResult(CustomCode.builder().message("备案编号不能为空").code(1999).success(false).build());
//		}
//
//		if (evaluationApprovalService.change(evaluationApproval)){
//			objResult = new ObjResult(CommonCode.SUCCESS);
//			return objResult;
//		}else {
//			objResult = new ObjResult(CommonCode.FAIL);
//			return objResult;
//		}
//	}
//	// todo excel 相关先不处理
////	/**
////	 * 输出excel前置
////	 */
////	@PostMapping("/preexport")
////	public R<String> preexport(@RequestBody String jsonString){
////		String md5= DigestUtil.hmacMd5Hex(jsonString, SecureUtil.getUserId() +"");
////		File file=evaluationApprovalService.exportExcel(JSON.parseObject(jsonString));
////		return  R.data(EvaluationApprovalCache.putJsonByKey(md5,file));
////	}
////	/**
////	 * 输出excel
////	 */
////	@GetMapping("/export/{key}")
////	@ApiOperationSupport(order = 7)
////	@ApiOperation(value = "输出", notes = "传入json")
////	public ResponseEntity<FileSystemResource> export(@PathVariable String key) {
////		return FileTools.exportFile(EvaluationApprovalCache.getJsonByKey(key));
////	}
//	/**
//	 * 打印
//	 */
//	@GetMapping("/buildpdf/{id}")
//	@PassToken
//	public ResponseEntity<FileSystemResource> buildPdf(@PathVariable Long id) {
//		return FileTools.exportPdf(evaluationApprovalService.buildpdf(id));
//	}
//}
